package com.pearadmin.pro.modules.school.rest;

import com.pearadmin.pro.modules.school.domain.TeachingMaterial;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import  com.pearadmin.pro.modules.school.domain.TeachingMaterial;
import  com.pearadmin.pro.modules.school.param.TeachingMaterialRequest;
import  com.pearadmin.pro.modules.school.service.TeachingMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 教材Controller
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Api(tags = {"教材"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"teachingMaterial/teachingMaterial")
public class TeachingMaterialController extends BaseController
{
    @Resource
    private TeachingMaterialService teachingMaterialService;

    /**
     * 查询教材列表
     *  @param request 查询参数
     *  @return {@link Result}
     */
    @GetMapping("/page")
    @Log(title = "教材列表")
    @ApiOperation(value = "教材列表")
    public Result<TeachingMaterial> list(TeachingMaterialRequest teachingMaterialRequest)
    {
        return success(teachingMaterialService.page(teachingMaterialRequest));
    }


    /**
     * 新增保存教材
     * @param teachingMaterial 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增教材")
    @ApiOperation(value = "新增教材")
    public Result save(@RequestBody TeachingMaterial teachingMaterial)
    {
        return auto(teachingMaterialService.save(teachingMaterial));
    }

    /**
     * 查询教材详情
     *
     * @param id 教材ID
     * @return 教材
     */
    @GetMapping("/selectById")
    @Log(title = "查询教材详情")
    @ApiOperation(value = "查询教材详情")
    public Result<TeachingMaterial> selectById(@RequestParam Long id)
    {
        return success(teachingMaterialService.selectTeachingMaterialById(id));
    }



    /**
     * 修改保存教材
     * @param teachingMaterial 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改教材")
    @ApiOperation(value = "修改教材")
    public Result update(@RequestBody TeachingMaterial teachingMaterial)
    {
        return auto(teachingMaterialService.updateById(teachingMaterial));
    }


    /**
     * 删除保存教材
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除教材")
    @ApiOperation(value = "删除教材")
    public Result remove(@RequestParam Long id)
    {
        return auto(teachingMaterialService.removeById(id));
    }

    /**
    * 批量删除教材
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除教材")
    @ApiOperation(value = "批量删除教材")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(teachingMaterialService.removeByIds(ids));
    }

}
